/* --------------------------------------
 * Copyright 2008 Jean-Matthieu BARBIER
 * --------------------------------------
 * This file is part of QLocatePC.
 *
 * QLocatePC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * QLocatePC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with QLocatePC.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef HTTPLOCATE_H
#define HTTPLOCATE_H

#include <QObject>
#include <QHttp>
#include <QTimer>
#include "setup.h"

/**
 * Send localisation infos to remote server.
 */
class QLocatePCHttpLocate : public QObject {
  Q_OBJECT
  
  public:
    QLocatePCHttpLocate(QObject *parent=0);
    bool makeUrl(const QLocatePCSetupData* settings, QUrl* url,const int mode);
    int goLocate( QLocatePCSetupData *settings, int mode);
    /**
    * Actions of QLocatePCHttpLocate.
    */
    static const int actionLocate = 1;
    static const int actionSetup = 2;
  private: 
    QHttp *http;
    QTimer *timer;
    bool daemonrunning;
    int daemoninterval;
  signals:
    void locSuccess(QString);
    void locFailed(QString);
    void daemonKilled();
    void daemonLaunched();
  public slots:
    void updateDaemon();
    void goSilentLocate();
  private slots:
    void httpDone(bool status);
    void responseReceived(const QHttpResponseHeader&);
    void daemonCycle();
};
#endif
